package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.LandmarkDetailCommend;
import cn.wolfcode.trip.base.domain.LmTicketCatalogBig;
import cn.wolfcode.trip.base.mapper.LandmarkDetailCommendMapper;
import cn.wolfcode.trip.base.query.LandmarkDetailComQueryObject;
import cn.wolfcode.trip.base.service.ILandmarkDetailCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LandmarkDetailCommendServiceImpl implements ILandmarkDetailCommendService {
    @Autowired
    private LandmarkDetailCommendMapper landmarkDetailCommendMapper;


    @Override
    public void save(LandmarkDetailCommend landmarkDetailCommend) {
        landmarkDetailCommendMapper.insert(landmarkDetailCommend);
    }

    @Override
    public void delete(Long id) {
        landmarkDetailCommendMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<LandmarkDetailCommend> selectAll() {
        return landmarkDetailCommendMapper.selectAll();
    }

    @Override
    public void update(LandmarkDetailCommend landmarkDetailCommend) {
        landmarkDetailCommendMapper.updateByPrimaryKey(landmarkDetailCommend);
    }

    @Override
    public LandmarkDetailCommend get(Long id) {
        return landmarkDetailCommendMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo getCommendByCbId(LandmarkDetailComQueryObject qo2) {
        //当前页,和页面显示条数
        PageHelper.startPage(qo2.getCurrentPage(),qo2.getPageSize());
        //准备基本sql
        List<LandmarkDetailCommend> list = landmarkDetailCommendMapper.getCommendByCbId(qo2);
        return new PageInfo(list);
    }

    @Override
    public List<LandmarkDetailCommend> getCommendByCatalogBigId(Long specialSubCommendId) {
        return landmarkDetailCommendMapper.getCommendByCatalogBigId(specialSubCommendId);
    }

    @Override
    public Object insertRelation(Long specialSubCommendId,Long ticketId) {
        if(specialSubCommendId!=null){
            landmarkDetailCommendMapper.deleteRelation(specialSubCommendId);
        }
        return landmarkDetailCommendMapper.insertRelation(specialSubCommendId,ticketId);
    }

}
